#ifdef _WIN32
#ifndef __PROCESSDUMP_H__
#define __PROCESSDUMP_H__


#include <Windows.h>
#include <DbgHelp.h>
#include <stdio.h>
#include <string>

typedef struct _EnumSysmbolsParam
{
	HANDLE hProcess;
	CONTEXT* Context;
	FILE* Fp;
}EnumSysmbolsParam;

#define PROCESSDUMPFILE "MiniDump"

class CProcessDump
{
public:
	CProcessDump()
	{
		Begin();
	}
public:
	bool Begin()
	{
		SetErrorMode(SEM_FAILCRITICALERRORS);
		SetUnhandledExceptionFilter(ServerDumpUnhandledExceptionFilter);
		return true;
	}
	static LONG WINAPI ServerDumpUnhandledExceptionFilter(struct _EXCEPTION_POINTERS *ExceptionInfo);

	static LONG MiniDump(struct _EXCEPTION_POINTERS *ExceptionInfo);

	static bool OutputStack(struct _EXCEPTION_POINTERS *ExceptionInfo);
	static BOOL CALLBACK EnumSysmbolsFunc(PSYMBOL_INFO pSymInfo,ULONG SymbolSize,PVOID UserContext);
	static DWORD GetSymbolAddress(PSYMBOL_INFO pSymbolInfo,EnumSysmbolsParam* Param);
	static std::string GetTypeName(int typeID, HANDLE hProcess, DWORD64 modBase);
	static std::string GetBaseTypeName(int typeID, HANDLE hProcess, DWORD64 modBase);
	static std::string GetPointerTypeName(int typeID, HANDLE hProcess, DWORD64 modBase);
	static std::string GetArrayTypeName(int typeID, HANDLE hProcess, DWORD64 modBase);

};

#endif
#endif
